<?php
include('class/class_connect.php');
include('class/class_page.php');
include('class/class_comments.php');
include('class/class_news.php');
include('class/class_address.php');
include('class/class_workdays.php');
include('class/class_rating.php');
include('class/class_acts.php');
include('class/tabs/class_tabs.php');
include('class/abstract/class_mainObjectInfo.php');
include('class/city_rus.php');
include('class/class_checkGetData.php');
include('class/class_prices.php');

$aCheck=new checkGetData('f');
$aCheck->checkTableId($_GET['city'], $_GET['id']);

$aComment=new comments('f', $_GET['city'], $_GET['id']);
$aComment->addComment();
session_start();


class aFirmPage extends page
{
	var $row=array();
	var $cityRus;
	function __construct()
	{
		$aConnect=new connect('f');
		$this->row=mysql_fetch_array($aConnect->select_all($_GET['city'], "WHERE id='".$_GET['id']."'"));
		$this->cityRus=new city_rus_class();
		parent::__construct();
	}
	function title()
	{
		echo $this->row['name'].' '.$this->cityRus->city_rus_im($_GET['city']);
	}
	function maincontent()
	{
		echo ('
		<div class="photoFrame">
		</div>
		<script type="text/javascript" src="jquery/jquery.js">
			</script>
		<div class="route">
			<div class="routeEl">
				<a href="division.php?city='.$_GET['city'].'&division='.$this->row['division'].'">'.$this->row['division'].'</a>
			</div>
			<div class="routeEl">
				<a href="firms_list.php?city='.$_GET['city'].'&subdiv='.$this->row['subdiv'].'">'.$this->row['subdiv'].'</a>
			</div>
			<div class="routeEl">
				'.$this->row['name'].'
			</div>
		</div>
		');
		$aFirmInfo=new aFirmInfo($this->row);
    	$aTab=new aFirmTabs();
	}
	function metaData()
	{
		$robots='INDEX,FOLLOW';
		$description=$this->row['name'].' в городе '.$this->cityRus->city_rus_im($_GET['city']).'.
		Адреса, телефоны, сайт, часы работы, отзывы, цены, фотографии, события и другая информация о фирмe '.$this->row['name'];
		$keywords=$this->row['name'].','.$this->row['short'].','.$this->cityRus->city_rus_im($_GET['city']).','.
		str_replace(' ',',',$this->row['subdiv']).','.str_replace(' ',',',$this->row['division']);
		return array('name'=>array('Robots'=>$robots,
 								   'Description'=>$description,
 								   'Keywords'=>$keywords,
 								   ),
 					);
	}
}

class aFirmTabs extends tabs
{
	var $row=array();
	function __construct()
	{
		$aConnect=new connect('p');
		$row=mysql_fetch_array($aConnect->select_all($_GET['city'], "WHERE firms_id='".$_GET['id']."'"));
		($row['tab_name'])?$price=$row['tab_name']:$price="Прайс-лист";
		$labels=array('Отзывы', 'Новости', 'О фирме', $price, 'События');
		parent::__construct($labels);

	}
	function content0()
	{
		$aComment=new comments('f', $_GET['city'], $_GET['id']);
		$comConnect=new connect('fc');
		$comNum=mysql_num_rows(connect::select_all($_GET['city'], "WHERE f_id='".$_GET['id']."'"));
		if($comNum==0)$comsName="Будьте первым";
		else if($comNum<=3)$comsName="Все отзывы";
		else $comsName="Последние отзывы";
		echo ('<div class="tabHeader"><h3>'.$comsName.'</h3></div>');
		$aComment->showComments(3);
		$aComment->commentForm($_SESSION['login']);
	}
	function content1()
	{
		$aNews=new news('firms', $_GET['city'], $_GET['id']);
		$newsConnect=new connect('fn');
		$newsesNum=mysql_num_rows(connect::select_all($_GET['city'], "WHERE firms_id='".$_GET['id']."'"));
		if($newsesNum==0)$newsesName="Новостей нет";
		else if($newsesNum<=3)$newsesName="Все новости";
		else $newsesName="Последние новости";
		echo ('<div class="tabHeader"><h3>'.$newsesName.'</h3></div>');
		$aNews->showNews('fullnews.php?city='.$_GET['city'].'&obj=firms&id='.$_GET['id'].'&news_id=', 4, 200);

	}
	function content2()
	{
		$aConnect=new connect('f');
		$row=mysql_fetch_array($aConnect->select_all($_GET['city'], "WHERE id='".$_GET['id']."'"));
		$text=nl2br($row['stext']);
		echo ('
		<script type="text/javascript" src="scripts/showPhoto.js">
		</script>
		<link rel="stylesheet" type="text/css" href="style/aboutFirms.css" />

		<div class="firmsPhotos" align="center">
			<table class="photoTable" border="0">
				<tr>
			');
			if(file_exists('pictures/firmsphoto/'.$_GET['city'].'/'.$_GET['id'].''))
			{
				for($i=1; $i<=5; $i++)
				{
					if(file_exists('pictures/firmsphoto/'.$_GET['city'].'/'.$_GET['id'].'/'.$i.'.jpg'))
					{
						echo ('
						<td class="aPhotoTr" align="center">
							<img class="firmsPhoto" id="firmsPhoto'.$i.'" src="pictures/firmsphoto/'.$_GET['city'].'/'.$_GET['id'].'/'.$i.'.jpg" height="100">
						</td>
						');
					}
					else if(file_exists('pictures/firmsphoto/'.$_GET['city'].'/'.$_GET['id'].'/'.$i.'.php'))
					{
						echo ('
						<td class="aPhotoTr" align="center">
							<img class="firmsPhoto" id="firmsPhoto'.$i.'" src="');
							include('pictures/firmsphoto/'.$_GET['city'].'/'.$_GET['id'].'/'.$i.'.php');
							echo ('
							" height="100">
						</td>
						');
					}
				}
			}
			echo ('
				</tr>
			</table>
		</div>
		<div class="tabHeader">
			<h4>'.$row['text_title'].'</h4>
		</div>
		<div class="firmText">
			'.$text.'
		</div>
		<div class="firmsPhotos" align="center">
			<table class="photoTable" border="0">
				<tr>
			');
			if(file_exists('pictures/firmsphoto/'.$_GET['city'].'/'.$_GET['id'].''))
			{
				for($i=6; $i<=10; $i++)
				{
					if(file_exists('pictures/firmsphoto/'.$_GET['city'].'/'.$_GET['id'].'/'.$i.'.jpg'))
					{
						echo ('
						<td class="aPhotoTr" align="center">
							<img class="firmsPhoto" id="firmsPhoto'.$i.'" src="pictures/firmsphoto/'.$_GET['city'].'/'.$_GET['id'].'/'.$i.'.jpg" height="100">
						</td>
						');
					}
				}
			}
			echo ('
				</tr>
			</table>
		</div>
		');
	}
	function content3()
	{
		$aConnect=new connect('f');
    	$firmsRow=mysql_fetch_array($aConnect->select_all($_GET['city'], "WHERE id='".$_GET['id']."'"));
    	$aConnect=new connect('p');
    	$res=$aConnect->select_all($_GET['city'], "WHERE firms_id='".$_GET['id']."'");
    	if($priceExists=mysql_num_rows($res))
    	{
    		echo '
    		<link rel="stylesheet" type="text/css" href="style/price.css" />
    		';
    		$row=mysql_fetch_array($res);
    		echo ('
    		<div class="prices" align="center">
	    		<div class="showPrice" align="center">
	    		');
	    			$aShowPrice=new showPrice($row['stext']);
	    			$aShowPrice->showPrices($row['stext'], false, false, array(2,1));//, $firmsRow['net_id']);
	    		echo ('
	    		</div>
    		</div>
    		<div class="showPriceButton">
    			<a class="belink" href="prices.php?city='.$_GET['city'].'&id='.$_GET['id'].'">Показать полностью</a>
    		</div>
    		');
    	}
    	else
    	{
    		echo ('
    		<div class="tabHeader"><h3>Прайс-лист не заполнен</h3></div>
    		');
    	}
	}
	function content4()
	{
		$act=new acts();
		$act->showActs('firms', 4, 200, $_GET['id'], false, "950px");
	}
}

class aFirmInfo extends mainObjectInfo
{
	var $row;
	function __construct($row=array())
	{
		$this->row=$row;
		parent::__construct();
	}
	function showPic()
	{
		echo ('
		<img src="pictures/firmspics/'.$_GET['city'].'/'.$this->row['id'].'.jpg" title="'.$this->name.'">
		');
		$aFirmRating=new rating('f');
		$aFirmRating->rating($_GET['city'], $this->row['id']);
	}
	function showAddress()
	{
		$address=new address();
		$address->showSeveralAddresses($this->row['address'], $this->row['link']);
	}
	function showshort()
	{
		echo $this->row['short'];
	}
	function showName()
	{
		echo $this->row['name'];
	}
}
class showPrice extends prices
{
	function showPrices($tables, $a, $b, $limit){
		parent::showTables($tables, $a, $b, $limit);
	}
	function showTd($tdClass, $tdId, $tdValue, $temp='')
	{
		if($tdClass=='img')
			echo '<img src="pictures/pricepics/'.$_GET['city'].'/'.$_GET['id'].'/'.$tdId.'.jpg?'.rand().'" />';
		elseif($tdClass=='name' || $tdClass=='brend' || $tdClass=='model')
			echo '<a href="products.php?city='.$_GET['city'].'&product='.$tdValue.'">'.$tdValue.'</a>';
		else
			echo $tdValue;
	}
	function showHeader($table, $header=array())
	{
		$headerEmty=true;
		foreach($header as $key=>$vol)
		{
			if($vol && $vol!='')$headerEmty=false;
		}
		if($header && !$headerEmpty)
		{
			echo ('
			<tr id="headerTr'.$table.'" class="headerTr">
			');
			for($i=1; $i<=count($header); $i++)
			{
				echo ('
				<td id="headerTd'.$table.$i.'" class="headerTd">
					'.$header[$i-1].'
				</td>
				');
			}
			echo ('
			</tr>
			');
		}
	}
	function showTabName($tabName, $table)
	{
		echo ('
		<h3>'.$tabName.'</h3>
		');
	}
	function showColType($table, $colType){}
}


$aPage=new aFirmPage();

?>